﻿@model BattleThis.Core.Map

<script type="text/javascript">
    $(document).ready(function () {
        //        $(".GameField a").click(function () {
        //            $(this).attr("src", "/Content/themes/base/images/Fields/Border.png");
        //        });
        $("a").click(function (event) {
            event.preventDefault();

            if (this.type === "unit") { //to refactor: constant as javascript obj from mvc
                $(".fogOfWar").show();
                var titleId = $(this).parent().get(0).id;
                var tmp = titleId.split("_");
                var pos = parseInt(tmp[0]); //separator mitteilen!
                var row = parseInt(tmp[1]);

                var top = pos + 1;
                var bottom = pos - 1;
                var left = row - 1;
                var right = row + 1;

                $("#" + titleId).find(".fogOfWar").hide();
                $("#" + top + "_" + row).find(".fogOfWar").hide();
                $("#" + bottom + "_" + row).find(".fogOfWar").hide();
                $("#" + pos + "_" + left).find(".fogOfWar").hide();
                $("#" + pos + "_" + right).find(".fogOfWar").hide();

                $("#" + pos + "_" + right).find(".fogOfWar").hide();
                $("#" + top + "_" + row).find("a").click(function (event) {
                    event.preventDefault();


                    $(this).find(".Unit").fadeOut("slow", function () {
                        $("#" + pos + "_" + left + " .fogOfWar").after(this);
                        $(this).fadeIn("slow");
                    });
                    $(this).parent().find(".UnitInfos").fadeOut("slow", function () {
                        $("#" + pos + "_" + left).find("a").before(this);
                        $(this).fadeIn("slow");
                    });

                })
            }
        });
    });
</script>

<div style="width: 100%; height: 100%; background-color: black;" id="gameMap">

@foreach( var item in this.Model.Fields.Columns )
{
  <div class="@(item.First().Position.IsEven() ? "row" : "row_Alternating")">
	@this.Html.DisplayFor( model => model.Fields )
  </div>  
}

</div>